{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import _pickle as cPickle\n",
    "from collections import defaultdict"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 获取存储的pkl数据并且操作\n",
    "1. recommand表的样子：\n",
    "    - recommand['location']:\n",
    "        - {age0:[item1,item2,]},\n",
    "        - {age1:[item1,item2,]}\n",
    "2. location下面的每个age都给推荐，其中推荐规则是：\n",
    "    - 先选location/age下面的每个item，按照被打分的次数排序\n",
    "    - 然后取item被打分次数的中位数\n",
    "    - 取均值\n",
    "    - 取均值在5分以上\n",
    "    - 放到字典的value值里"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>location</th>\n",
       "      <th>age</th>\n",
       "      <th>item_id</th>\n",
       "      <th>rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>usa</td>\n",
       "      <td>2</td>\n",
       "      <td>0195153448</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7</td>\n",
       "      <td>usa</td>\n",
       "      <td>0</td>\n",
       "      <td>034542252</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8</td>\n",
       "      <td>canada</td>\n",
       "      <td>0</td>\n",
       "      <td>0002005018</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>8</td>\n",
       "      <td>canada</td>\n",
       "      <td>0</td>\n",
       "      <td>0060973129</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8</td>\n",
       "      <td>canada</td>\n",
       "      <td>0</td>\n",
       "      <td>0374157065</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   user_id location  age     item_id  rating\n",
       "0        2      usa    2  0195153448     0.0\n",
       "1        7      usa    0   034542252     0.0\n",
       "2        8   canada    0  0002005018     5.0\n",
       "3        8   canada    0  0060973129     0.0\n",
       "4        8   canada    0  0374157065     0.0"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data=cPickle.load(\n",
    "    open('./data/train_data.pkl','rb'))\n",
    "train_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3    4815\n",
       "0    3011\n",
       "4     521\n",
       "2      68\n",
       "1      66\n",
       "5       1\n",
       "Name: age, dtype: int64"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_data[train_data['location']=='italy']['age'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 推荐\n",
    "- 什么给推荐\n",
    "    - 所有的item都列出来\n",
    "    - 每个item下面有多少user_id打过分\n",
    "        - 如果只有一两个或者少于5个就不采纳了（判断标准：max(np.percentile(item_id.value_counts(),75),5)）\n",
    "        - 如果多于5个\n",
    "            - 取均值，当均值小于等于5不采纳\n",
    "            - 当均值大于5采纳\n",
    "            - 按照均值排序\n",
    "            - 取最上面20个放到列表推荐\n",
    "- 什么不给推荐\n",
    "    - rating少于5个\n",
    "    - 评分均值小于5分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "运行到 australia 0\n",
      "运行到 australia 1\n",
      "运行到 australia 2\n",
      "运行到 australia 3\n",
      "运行到 australia 4\n",
      "运行到 australia 5\n",
      "运行到 canada 0\n",
      "运行到 canada 1\n",
      "运行到 canada 2\n",
      "运行到 canada 3\n",
      "运行到 canada 4\n",
      "运行到 canada 5\n",
      "运行到 france 0\n",
      "运行到 france 1\n",
      "运行到 france 2\n",
      "运行到 france 3\n",
      "运行到 france 4\n",
      "运行到 france 5\n",
      "运行到 germany 0\n",
      "运行到 germany 1\n",
      "运行到 germany 2\n",
      "运行到 germany 3\n",
      "运行到 germany 4\n",
      "运行到 germany 5\n",
      "运行到 italy 0\n",
      "运行到 italy 1\n",
      "运行到 italy 2\n",
      "运行到 italy 3\n",
      "运行到 italy 4\n",
      "运行到 italy 5\n",
      "运行到 new zealand 0\n",
      "运行到 new zealand 1\n",
      "运行到 new zealand 2\n",
      "运行到 new zealand 3\n",
      "运行到 new zealand 4\n",
      "运行到 new zealand 5\n",
      "运行到 other 0\n",
      "运行到 other 1\n",
      "运行到 other 2\n",
      "运行到 other 3\n",
      "运行到 other 4\n",
      "运行到 other 5\n",
      "运行到 portugal 0\n",
      "运行到 portugal 1\n",
      "运行到 portugal 2\n",
      "运行到 portugal 3\n",
      "运行到 portugal 4\n",
      "运行到 portugal 5\n",
      "运行到 spain 0\n",
      "运行到 spain 1\n",
      "运行到 spain 2\n",
      "运行到 spain 3\n",
      "运行到 spain 4\n",
      "运行到 spain 5\n",
      "运行到 united kingdom 0\n",
      "运行到 united kingdom 1\n",
      "运行到 united kingdom 2\n",
      "运行到 united kingdom 3\n",
      "运行到 united kingdom 4\n",
      "运行到 united kingdom 5\n",
      "运行到 usa 0\n",
      "运行到 usa 1\n",
      "运行到 usa 2\n",
      "运行到 usa 3\n",
      "运行到 usa 4\n",
      "运行到 usa 5\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "defaultdict(dict,\n",
       "            {'australia': {0: [('0099771519', 7.0), ('1857022424', 5.33)],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: [('0007170866', 6.14),\n",
       "               ('1875989218', 6.0),\n",
       "               ('0860074382', 5.91),\n",
       "               ('0140008535', 5.86),\n",
       "               ('0385335482', 5.71),\n",
       "               ('0553279556', 5.67),\n",
       "               ('0743225082', 5.33),\n",
       "               ('0949206318', 5.17)],\n",
       "              4: [('0091867770', 5.17)],\n",
       "              5: []},\n",
       "             'canada': {0: [('0140067477', 7.86),\n",
       "               ('0553250426', 7.12),\n",
       "               ('0060392452', 7.0),\n",
       "               ('0676974791', 6.83),\n",
       "               ('0060959037', 6.38),\n",
       "               ('0771099894', 6.25),\n",
       "               ('0446667900', 6.12),\n",
       "               ('0553375407', 6.0),\n",
       "               ('1550541129', 6.0),\n",
       "               ('0671011375', 6.0),\n",
       "               ('0440224764', 5.88),\n",
       "               ('0385486804', 5.86),\n",
       "               ('0771055706', 5.85),\n",
       "               ('0140096825', 5.83),\n",
       "               ('074343627X', 5.78),\n",
       "               ('067976402X', 5.76),\n",
       "               ('0446530522', 5.67),\n",
       "               ('0451204891', 5.57),\n",
       "               ('0446364193', 5.56),\n",
       "               ('0786868716', 5.5)],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: [('0140042393', 8.33),\n",
       "               ('0552137030', 8.29),\n",
       "               ('0060915544', 8.17),\n",
       "               ('0836220889', 7.83),\n",
       "               ('0836218256', 7.67),\n",
       "               ('0679735771', 7.62),\n",
       "               ('1853260002', 7.5),\n",
       "               ('1573225517', 7.33),\n",
       "               ('0671868691', 7.17),\n",
       "               ('0446532231', 7.15),\n",
       "               ('038542017X', 7.14),\n",
       "               ('0451163524', 7.0),\n",
       "               ('0440224764', 7.0),\n",
       "               ('0771060548', 6.89),\n",
       "               ('0064471047', 6.83),\n",
       "               ('0553287893', 6.83),\n",
       "               ('0451191145', 6.8),\n",
       "               ('0345348036', 6.75),\n",
       "               ('0385486804', 6.71),\n",
       "               ('0441172717', 6.71)],\n",
       "              4: [('0316666343', 7.57),\n",
       "               ('0676974805', 6.0),\n",
       "               ('0440213525', 5.57),\n",
       "               ('0515111279', 5.43),\n",
       "               ('034540288X', 5.29),\n",
       "               ('0676973094', 5.22)],\n",
       "              5: []},\n",
       "             'france': {0: [],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: [('2070408507', 7.33),\n",
       "               ('2266084372', 7.0),\n",
       "               ('2877302202', 6.8),\n",
       "               ('2253140872', 6.67),\n",
       "               ('2070744833', 6.57),\n",
       "               ('2290302155', 6.33),\n",
       "               ('2253144452', 6.17),\n",
       "               ('2226135022', 6.12),\n",
       "               ('2020306492', 6.0),\n",
       "               ('2290308285', 5.89),\n",
       "               ('2253150711', 5.71),\n",
       "               ('2070414574', 5.43),\n",
       "               ('2264027134', 5.38),\n",
       "               ('2070373630', 5.29),\n",
       "               ('2842051181', 5.2),\n",
       "               ('2266022504', 5.14),\n",
       "               ('0747532745', 5.12)],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'germany': {0: [('3423203668', 5.33),\n",
       "               ('3426029553', 5.25),\n",
       "               ('3453007867', 5.17)],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: [('3551551677', 9.5),\n",
       "               ('3551551693', 9.5),\n",
       "               ('3499224615', 7.83),\n",
       "               ('3442727952', 7.43),\n",
       "               ('3518100734', 7.33),\n",
       "               ('3442724686', 7.33),\n",
       "               ('3596215226', 7.3),\n",
       "               ('3423204206', 7.25),\n",
       "               ('3150000017', 7.14),\n",
       "               ('3426612704', 6.89),\n",
       "               ('3423205202', 6.88),\n",
       "               ('3423202947', 6.7),\n",
       "               ('3442442354', 6.67),\n",
       "               ('3551551685', 6.5),\n",
       "               ('340412846X', 6.33),\n",
       "               ('3257061269', 6.17),\n",
       "               ('3518380796', 6.17),\n",
       "               ('3499121581', 6.0),\n",
       "               ('3442421357', 6.0),\n",
       "               ('0552546933', 6.0)],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'italy': {0: [('8806142100', 6.33),\n",
       "               ('8826703132', 6.08),\n",
       "               ('884590184X', 6.0)],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: [('8845205118', 7.67),\n",
       "               ('8845915700', 7.17),\n",
       "               ('8817106259', 6.29),\n",
       "               ('8807816067', 6.18),\n",
       "               ('0743222229', 5.86),\n",
       "               ('8807817039', 5.83),\n",
       "               ('8807814684', 5.5),\n",
       "               ('8807812436', 5.33),\n",
       "               ('8845290077', 5.29),\n",
       "               ('8817106100', 5.25),\n",
       "               ('8807816059', 5.1),\n",
       "               ('8804342838', 5.09)],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'new zealand': {0: [], 1: [], 2: [], 3: [], 4: [], 5: []},\n",
       "             'other': {0: [('034536676X', 8.17),\n",
       "               ('0439064872', 7.44),\n",
       "               ('0316693251', 7.0),\n",
       "               ('0060008024', 6.86),\n",
       "               ('0385720106', 6.71),\n",
       "               ('0380789019', 6.5),\n",
       "               ('0446608955', 6.5),\n",
       "               ('0385484518', 6.5),\n",
       "               ('0671001795', 6.5),\n",
       "               ('0385335881', 6.5),\n",
       "               ('014100018X', 6.33),\n",
       "               ('044651652X', 6.33),\n",
       "               ('0060987103', 6.33),\n",
       "               ('0440180295', 6.17),\n",
       "               ('0553296981', 6.17),\n",
       "               ('0345339681', 6.17),\n",
       "               ('0345337662', 6.17),\n",
       "               ('0140298479', 6.14),\n",
       "               ('0375707972', 6.0),\n",
       "               ('074343627X', 6.0)],\n",
       "              1: [],\n",
       "              2: [('043935806X', 6.33)],\n",
       "              3: [('0553296981', 9.57),\n",
       "               ('0590353403', 8.5),\n",
       "               ('0439139597', 7.22),\n",
       "               ('0842329218', 7.14),\n",
       "               ('0439136350', 7.1),\n",
       "               ('0446310786', 7.0),\n",
       "               ('0312924585', 7.0),\n",
       "               ('0099800403', 6.5),\n",
       "               ('3257228007', 6.33),\n",
       "               ('0446605239', 6.22),\n",
       "               ('0345439104', 6.17),\n",
       "               ('0552134651', 6.14),\n",
       "               ('059035342X', 6.12),\n",
       "               ('0684872153', 6.0),\n",
       "               ('3492045170', 6.0),\n",
       "               ('1400032717', 6.0),\n",
       "               ('0684833395', 5.83),\n",
       "               ('043935806X', 5.82),\n",
       "               ('0679781587', 5.8),\n",
       "               ('0345353145', 5.76)],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'portugal': {0: [],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: [('038082101X', 9.0),\n",
       "               ('0439139600', 7.33),\n",
       "               ('9505156944', 6.33),\n",
       "               ('0380977788', 5.86),\n",
       "               ('002542730X', 5.75),\n",
       "               ('0460877305', 5.71),\n",
       "               ('0385721234', 5.5),\n",
       "               ('0811214982', 5.3),\n",
       "               ('9722113747', 5.17)],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'spain': {0: [],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: [('8445071416', 8.83),\n",
       "               ('8420616893', 8.62),\n",
       "               ('950491036X', 8.43),\n",
       "               ('8478886451', 8.4),\n",
       "               ('8408039369', 7.62),\n",
       "               ('8495501074', 7.43),\n",
       "               ('8440627203', 7.17),\n",
       "               ('8445071408', 7.0),\n",
       "               ('0452282152', 7.0),\n",
       "               ('8433914545', 6.62),\n",
       "               ('8423309223', 6.62),\n",
       "               ('8420656747', 6.33),\n",
       "               ('8432206407', 6.17),\n",
       "               ('8401328942', 6.14),\n",
       "               ('8432215333', 6.14),\n",
       "               ('8495616254', 6.0),\n",
       "               ('8472236552', 5.92),\n",
       "               ('8478884459', 5.89),\n",
       "               ('8432215007', 5.86),\n",
       "               ('8483140004', 5.83)],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'united kingdom': {0: [('0590660543', 6.33),\n",
       "               ('000649840X', 6.17),\n",
       "               ('0330367358', 6.0),\n",
       "               ('0749395990', 5.67),\n",
       "               ('0099771519', 5.33)],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: [('1844262553', 8.35),\n",
       "               ('1857231384', 7.0),\n",
       "               ('0552145424', 6.83),\n",
       "               ('0552134627', 6.67),\n",
       "               ('0440206154', 6.67),\n",
       "               ('0552131059', 6.62),\n",
       "               ('0552142379', 6.5),\n",
       "               ('0140621199', 6.43),\n",
       "               ('0722532938', 6.38),\n",
       "               ('0552149519', 6.2),\n",
       "               ('0380813815', 6.17),\n",
       "               ('0140287248', 6.17),\n",
       "               ('0064407667', 6.12),\n",
       "               ('0349107688', 6.0),\n",
       "               ('0786817070', 6.0),\n",
       "               ('0552134635', 5.9),\n",
       "               ('0140621091', 5.83),\n",
       "               ('0552128481', 5.83),\n",
       "               ('0552137030', 5.83),\n",
       "               ('0552131075', 5.7)],\n",
       "              4: [('1844262553', 8.5)],\n",
       "              5: []},\n",
       "             'usa': {0: [('0060256672', 9.33),\n",
       "               ('0971942315', 9.0),\n",
       "               ('0615116426', 8.45),\n",
       "               ('0140309578', 8.33),\n",
       "               ('0316735027', 8.33),\n",
       "               ('0553148001', 8.17),\n",
       "               ('0395977894', 8.1),\n",
       "               ('0877738513', 8.0),\n",
       "               ('0060248025', 8.0),\n",
       "               ('0553351397', 7.57),\n",
       "               ('0618231617', 7.5),\n",
       "               ('0441004520', 7.5),\n",
       "               ('1400032717', 7.5),\n",
       "               ('0689824750', 7.38),\n",
       "               ('0446606421', 7.33),\n",
       "               ('0967370167', 7.29),\n",
       "               ('0385509510', 7.22),\n",
       "               ('0877017883', 7.2),\n",
       "               ('0399140093', 7.14),\n",
       "               ('0060988258', 7.14)],\n",
       "              1: [('0064407667', 9.67),\n",
       "               ('0439139597', 8.33),\n",
       "               ('0439064872', 6.25),\n",
       "               ('059035342X', 5.73),\n",
       "               ('043935806X', 5.43),\n",
       "               ('014038572X', 5.43)],\n",
       "              2: [('0439064864', 9.29),\n",
       "               ('0451191137', 9.0),\n",
       "               ('0590353403', 9.0),\n",
       "               ('0380814021', 8.83),\n",
       "               ('043935806X', 8.38),\n",
       "               ('0802132758', 8.25),\n",
       "               ('0439139597', 8.21),\n",
       "               ('0451523377', 8.0),\n",
       "               ('0671027344', 7.92),\n",
       "               ('0440237688', 7.83),\n",
       "               ('0345342968', 7.64),\n",
       "               ('0440222028', 7.5),\n",
       "               ('0446608955', 7.4),\n",
       "               ('0345339738', 7.38),\n",
       "               ('0385729332', 7.33),\n",
       "               ('0316666343', 7.13),\n",
       "               ('0439136350', 7.12),\n",
       "               ('0440219078', 7.0),\n",
       "               ('0064472272', 7.0),\n",
       "               ('0812550706', 7.0)],\n",
       "              3: [('0066238501', 9.86),\n",
       "               ('0394800389', 9.83),\n",
       "               ('0517693119', 9.83),\n",
       "               ('0920668364', 9.67),\n",
       "               ('0395177111', 9.5),\n",
       "               ('0316779059', 9.0),\n",
       "               ('0060256737', 8.83),\n",
       "               ('0345318587', 8.33),\n",
       "               ('0394800133', 8.25),\n",
       "               ('0786867906', 8.17),\n",
       "               ('0930289234', 8.17),\n",
       "               ('0064471063', 8.11),\n",
       "               ('0811807843', 8.0),\n",
       "               ('0451183940', 7.88),\n",
       "               ('0312423799', 7.67),\n",
       "               ('0060921056', 7.67),\n",
       "               ('0440900794', 7.67),\n",
       "               ('0886775957', 7.57),\n",
       "               ('0671720147', 7.5),\n",
       "               ('1563890119', 7.5)],\n",
       "              4: [('0553377868', 8.86),\n",
       "               ('1579546463', 8.0),\n",
       "               ('0380977311', 7.86),\n",
       "               ('0553379615', 7.83),\n",
       "               ('0446532452', 7.57),\n",
       "               ('0446322180', 7.29),\n",
       "               ('0439064864', 7.22),\n",
       "               ('0451169514', 7.17),\n",
       "               ('0553802461', 7.12),\n",
       "               ('0553268937', 6.83),\n",
       "               ('0553582763', 6.83),\n",
       "               ('0385318782', 6.71),\n",
       "               ('0679457526', 6.7),\n",
       "               ('0140053204', 6.7),\n",
       "               ('0140133488', 6.67),\n",
       "               ('0446611638', 6.64),\n",
       "               ('0679721037', 6.57),\n",
       "               ('0399146008', 6.56),\n",
       "               ('0449006565', 6.5),\n",
       "               ('0345458915', 6.5)],\n",
       "              5: []}})"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "recommand_data=defaultdict(dict)\n",
    "for location,groupby_location in train_data.groupby('location'):\n",
    "    for age,groupby_location_age in groupby_location.groupby('age'):\n",
    "        print('运行到',location,age)\n",
    "        user_data=groupby_location_age\n",
    "        # boundary:item_id按照打分次数的75%取值（视频按照value值75%）\n",
    "        user_data_value_sort=user_data['item_id'].value_counts().sort_values(ascending=False)\n",
    "        boundary=max(np.percentile(user_data_value_sort,75),5)\n",
    "        boundary_data=user_data_value_sort[user_data_value_sort>boundary]\n",
    "        recommand=user_data[user_data['item_id'].isin(boundary_data.index)]\n",
    "        recommanded=recommand.groupby('item_id')['rating'].mean().sort_values(ascending=False)[:20]\n",
    "        recommand_data[location][age]=[(item,round(recommanded.loc[item],2)) for item in recommanded.index if recommanded.loc[item]>5 ]\n",
    "    \n",
    "recommand_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 因为italy在训练集中都没有5，所以手动补\n",
    "？？？这种因为数据集的划分，以及本来数据样本比较少的情况，导致划分的时候没有，自动的方法是？？？\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 如果推荐列表不够20个，需要全局找到top20，上面不够的，就补充进去"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('1844262553', 8.0),\n",
       " ('0439139597', 6.72),\n",
       " ('0439136350', 6.55),\n",
       " ('0439064864', 6.55),\n",
       " ('0877017883', 6.19),\n",
       " ('0618002227', 6.16),\n",
       " ('0590353403', 6.13),\n",
       " ('0671027344', 6.07),\n",
       " ('0385199570', 5.93),\n",
       " ('0771060548', 5.91),\n",
       " ('0156528207', 5.78),\n",
       " ('0618129022', 5.76),\n",
       " ('0552128481', 5.68),\n",
       " ('0552131059', 5.67),\n",
       " ('0811801802', 5.65),\n",
       " ('0670032379', 5.55),\n",
       " ('0812550706', 5.52),\n",
       " ('0375756981', 5.51),\n",
       " ('0670894605', 5.42),\n",
       " ('0811825558', 5.36)]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "top2000_data=train_data['item_id'].value_counts().sort_values(ascending=False)[:2000].index\n",
    "top20_data=train_data[\n",
    "        train_data['item_id'].isin(top2000_data)\n",
    "    ].groupby('item_id')['rating'].mean().sort_values(ascending=False)[:20]\n",
    "top20_data=[(index,round(top20_data.loc[index],2)) for index in top20_data.index]\n",
    "top20_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'collections.defaultdict'>\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[('0099771519', 7.0), ('1857022424', 5.33)]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(type(recommand_data))\n",
    "recommand_data['australia'][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "australia 0\n",
      "australia 1\n",
      "australia 2\n",
      "australia 3\n",
      "australia 4\n",
      "australia 5\n",
      "canada 0\n",
      "canada 1\n",
      "canada 2\n",
      "canada 3\n",
      "canada 4\n",
      "canada 5\n",
      "france 0\n",
      "france 1\n",
      "france 2\n",
      "france 3\n",
      "france 4\n",
      "france 5\n",
      "germany 0\n",
      "germany 1\n",
      "germany 2\n",
      "germany 3\n",
      "germany 4\n",
      "germany 5\n",
      "italy 0\n",
      "italy 1\n",
      "italy 2\n",
      "italy 3\n",
      "italy 4\n",
      "italy 5\n",
      "new zealand 0\n",
      "new zealand 1\n",
      "new zealand 2\n",
      "new zealand 3\n",
      "new zealand 4\n",
      "new zealand 5\n",
      "other 0\n",
      "other 1\n",
      "other 2\n",
      "other 3\n",
      "other 4\n",
      "other 5\n",
      "portugal 0\n",
      "portugal 1\n",
      "portugal 2\n",
      "portugal 3\n",
      "portugal 4\n",
      "portugal 5\n",
      "spain 0\n",
      "spain 1\n",
      "spain 2\n",
      "spain 3\n",
      "spain 4\n",
      "spain 5\n",
      "united kingdom 0\n",
      "united kingdom 1\n",
      "united kingdom 2\n",
      "united kingdom 3\n",
      "united kingdom 4\n",
      "united kingdom 5\n",
      "usa 0\n",
      "usa 1\n",
      "usa 2\n",
      "usa 3\n",
      "usa 4\n",
      "usa 5\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "defaultdict(dict,\n",
       "            {'australia': {0: [('0099771519', 7.0),\n",
       "               ('1857022424', 5.33),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51)],\n",
       "              1: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              2: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              3: [('0007170866', 6.14),\n",
       "               ('1875989218', 6.0),\n",
       "               ('0860074382', 5.91),\n",
       "               ('0140008535', 5.86),\n",
       "               ('0385335482', 5.71),\n",
       "               ('0553279556', 5.67),\n",
       "               ('0743225082', 5.33),\n",
       "               ('0949206318', 5.17),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76)],\n",
       "              4: [('0091867770', 5.17),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42)],\n",
       "              5: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)]},\n",
       "             'canada': {0: [('0140067477', 7.86),\n",
       "               ('0553250426', 7.12),\n",
       "               ('0060392452', 7.0),\n",
       "               ('0676974791', 6.83),\n",
       "               ('0060959037', 6.38),\n",
       "               ('0771099894', 6.25),\n",
       "               ('0446667900', 6.12),\n",
       "               ('0553375407', 6.0),\n",
       "               ('1550541129', 6.0),\n",
       "               ('0671011375', 6.0),\n",
       "               ('0440224764', 5.88),\n",
       "               ('0385486804', 5.86),\n",
       "               ('0771055706', 5.85),\n",
       "               ('0140096825', 5.83),\n",
       "               ('074343627X', 5.78),\n",
       "               ('067976402X', 5.76),\n",
       "               ('0446530522', 5.67),\n",
       "               ('0451204891', 5.57),\n",
       "               ('0446364193', 5.56),\n",
       "               ('0786868716', 5.5)],\n",
       "              1: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              2: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              3: [('0140042393', 8.33),\n",
       "               ('0552137030', 8.29),\n",
       "               ('0060915544', 8.17),\n",
       "               ('0836220889', 7.83),\n",
       "               ('0836218256', 7.67),\n",
       "               ('0679735771', 7.62),\n",
       "               ('1853260002', 7.5),\n",
       "               ('1573225517', 7.33),\n",
       "               ('0671868691', 7.17),\n",
       "               ('0446532231', 7.15),\n",
       "               ('038542017X', 7.14),\n",
       "               ('0451163524', 7.0),\n",
       "               ('0440224764', 7.0),\n",
       "               ('0771060548', 6.89),\n",
       "               ('0064471047', 6.83),\n",
       "               ('0553287893', 6.83),\n",
       "               ('0451191145', 6.8),\n",
       "               ('0345348036', 6.75),\n",
       "               ('0385486804', 6.71),\n",
       "               ('0441172717', 6.71)],\n",
       "              4: [('0316666343', 7.57),\n",
       "               ('0676974805', 6.0),\n",
       "               ('0440213525', 5.57),\n",
       "               ('0515111279', 5.43),\n",
       "               ('034540288X', 5.29),\n",
       "               ('0676973094', 5.22),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67)],\n",
       "              5: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)]},\n",
       "             'france': {0: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              1: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              2: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              3: [('2070408507', 7.33),\n",
       "               ('2266084372', 7.0),\n",
       "               ('2877302202', 6.8),\n",
       "               ('2253140872', 6.67),\n",
       "               ('2070744833', 6.57),\n",
       "               ('2290302155', 6.33),\n",
       "               ('2253144452', 6.17),\n",
       "               ('2226135022', 6.12),\n",
       "               ('2020306492', 6.0),\n",
       "               ('2290308285', 5.89),\n",
       "               ('2253150711', 5.71),\n",
       "               ('2070414574', 5.43),\n",
       "               ('2264027134', 5.38),\n",
       "               ('2070373630', 5.29),\n",
       "               ('2842051181', 5.2),\n",
       "               ('2266022504', 5.14),\n",
       "               ('0747532745', 5.12),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55)],\n",
       "              4: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              5: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)]},\n",
       "             'germany': {0: [('3423203668', 5.33),\n",
       "               ('3426029553', 5.25),\n",
       "               ('3453007867', 5.17),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52)],\n",
       "              1: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              2: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              3: [('3551551677', 9.5),\n",
       "               ('3551551693', 9.5),\n",
       "               ('3499224615', 7.83),\n",
       "               ('3442727952', 7.43),\n",
       "               ('3518100734', 7.33),\n",
       "               ('3442724686', 7.33),\n",
       "               ('3596215226', 7.3),\n",
       "               ('3423204206', 7.25),\n",
       "               ('3150000017', 7.14),\n",
       "               ('3426612704', 6.89),\n",
       "               ('3423205202', 6.88),\n",
       "               ('3423202947', 6.7),\n",
       "               ('3442442354', 6.67),\n",
       "               ('3551551685', 6.5),\n",
       "               ('340412846X', 6.33),\n",
       "               ('3257061269', 6.17),\n",
       "               ('3518380796', 6.17),\n",
       "               ('3499121581', 6.0),\n",
       "               ('3442421357', 6.0),\n",
       "               ('0552546933', 6.0)],\n",
       "              4: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              5: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)]},\n",
       "             'italy': {0: [('8806142100', 6.33),\n",
       "               ('8826703132', 6.08),\n",
       "               ('884590184X', 6.0),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52)],\n",
       "              1: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              2: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              3: [('8845205118', 7.67),\n",
       "               ('8845915700', 7.17),\n",
       "               ('8817106259', 6.29),\n",
       "               ('8807816067', 6.18),\n",
       "               ('0743222229', 5.86),\n",
       "               ('8807817039', 5.83),\n",
       "               ('8807814684', 5.5),\n",
       "               ('8807812436', 5.33),\n",
       "               ('8845290077', 5.29),\n",
       "               ('8817106100', 5.25),\n",
       "               ('8807816059', 5.1),\n",
       "               ('8804342838', 5.09),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07)],\n",
       "              4: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              5: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)]},\n",
       "             'new zealand': {0: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              1: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              2: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              3: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              4: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              5: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)]},\n",
       "             'other': {0: [('034536676X', 8.17),\n",
       "               ('0439064872', 7.44),\n",
       "               ('0316693251', 7.0),\n",
       "               ('0060008024', 6.86),\n",
       "               ('0385720106', 6.71),\n",
       "               ('0380789019', 6.5),\n",
       "               ('0446608955', 6.5),\n",
       "               ('0385484518', 6.5),\n",
       "               ('0671001795', 6.5),\n",
       "               ('0385335881', 6.5),\n",
       "               ('014100018X', 6.33),\n",
       "               ('044651652X', 6.33),\n",
       "               ('0060987103', 6.33),\n",
       "               ('0440180295', 6.17),\n",
       "               ('0553296981', 6.17),\n",
       "               ('0345339681', 6.17),\n",
       "               ('0345337662', 6.17),\n",
       "               ('0140298479', 6.14),\n",
       "               ('0375707972', 6.0),\n",
       "               ('074343627X', 6.0)],\n",
       "              1: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              2: [('043935806X', 6.33),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42)],\n",
       "              3: [('0553296981', 9.57),\n",
       "               ('0590353403', 8.5),\n",
       "               ('0439139597', 7.22),\n",
       "               ('0842329218', 7.14),\n",
       "               ('0439136350', 7.1),\n",
       "               ('0446310786', 7.0),\n",
       "               ('0312924585', 7.0),\n",
       "               ('0099800403', 6.5),\n",
       "               ('3257228007', 6.33),\n",
       "               ('0446605239', 6.22),\n",
       "               ('0345439104', 6.17),\n",
       "               ('0552134651', 6.14),\n",
       "               ('059035342X', 6.12),\n",
       "               ('0684872153', 6.0),\n",
       "               ('3492045170', 6.0),\n",
       "               ('1400032717', 6.0),\n",
       "               ('0684833395', 5.83),\n",
       "               ('043935806X', 5.82),\n",
       "               ('0679781587', 5.8),\n",
       "               ('0345353145', 5.76)],\n",
       "              4: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              5: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)]},\n",
       "             'portugal': {0: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              1: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              2: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              3: [('038082101X', 9.0),\n",
       "               ('0439139600', 7.33),\n",
       "               ('9505156944', 6.33),\n",
       "               ('0380977788', 5.86),\n",
       "               ('002542730X', 5.75),\n",
       "               ('0460877305', 5.71),\n",
       "               ('0385721234', 5.5),\n",
       "               ('0811214982', 5.3),\n",
       "               ('9722113747', 5.17),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78)],\n",
       "              4: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              5: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)]},\n",
       "             'spain': {0: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              1: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              2: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              3: [('8445071416', 8.83),\n",
       "               ('8420616893', 8.62),\n",
       "               ('950491036X', 8.43),\n",
       "               ('8478886451', 8.4),\n",
       "               ('8408039369', 7.62),\n",
       "               ('8495501074', 7.43),\n",
       "               ('8440627203', 7.17),\n",
       "               ('8445071408', 7.0),\n",
       "               ('0452282152', 7.0),\n",
       "               ('8433914545', 6.62),\n",
       "               ('8423309223', 6.62),\n",
       "               ('8420656747', 6.33),\n",
       "               ('8432206407', 6.17),\n",
       "               ('8401328942', 6.14),\n",
       "               ('8432215333', 6.14),\n",
       "               ('8495616254', 6.0),\n",
       "               ('8472236552', 5.92),\n",
       "               ('8478884459', 5.89),\n",
       "               ('8432215007', 5.86),\n",
       "               ('8483140004', 5.83)],\n",
       "              4: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              5: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)]},\n",
       "             'united kingdom': {0: [('0590660543', 6.33),\n",
       "               ('000649840X', 6.17),\n",
       "               ('0330367358', 6.0),\n",
       "               ('0749395990', 5.67),\n",
       "               ('0099771519', 5.33),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65)],\n",
       "              1: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              2: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)],\n",
       "              3: [('1844262553', 8.35),\n",
       "               ('1857231384', 7.0),\n",
       "               ('0552145424', 6.83),\n",
       "               ('0552134627', 6.67),\n",
       "               ('0440206154', 6.67),\n",
       "               ('0552131059', 6.62),\n",
       "               ('0552142379', 6.5),\n",
       "               ('0140621199', 6.43),\n",
       "               ('0722532938', 6.38),\n",
       "               ('0552149519', 6.2),\n",
       "               ('0380813815', 6.17),\n",
       "               ('0140287248', 6.17),\n",
       "               ('0064407667', 6.12),\n",
       "               ('0349107688', 6.0),\n",
       "               ('0786817070', 6.0),\n",
       "               ('0552134635', 5.9),\n",
       "               ('0140621091', 5.83),\n",
       "               ('0552128481', 5.83),\n",
       "               ('0552137030', 5.83),\n",
       "               ('0552131075', 5.7)],\n",
       "              4: [('1844262553', 8.5),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42)],\n",
       "              5: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)]},\n",
       "             'usa': {0: [('0060256672', 9.33),\n",
       "               ('0971942315', 9.0),\n",
       "               ('0615116426', 8.45),\n",
       "               ('0140309578', 8.33),\n",
       "               ('0316735027', 8.33),\n",
       "               ('0553148001', 8.17),\n",
       "               ('0395977894', 8.1),\n",
       "               ('0877738513', 8.0),\n",
       "               ('0060248025', 8.0),\n",
       "               ('0553351397', 7.57),\n",
       "               ('0618231617', 7.5),\n",
       "               ('0441004520', 7.5),\n",
       "               ('1400032717', 7.5),\n",
       "               ('0689824750', 7.38),\n",
       "               ('0446606421', 7.33),\n",
       "               ('0967370167', 7.29),\n",
       "               ('0385509510', 7.22),\n",
       "               ('0877017883', 7.2),\n",
       "               ('0399140093', 7.14),\n",
       "               ('0060988258', 7.14)],\n",
       "              1: [('0064407667', 9.67),\n",
       "               ('0439139597', 8.33),\n",
       "               ('0439064872', 6.25),\n",
       "               ('059035342X', 5.73),\n",
       "               ('043935806X', 5.43),\n",
       "               ('014038572X', 5.43),\n",
       "               ('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67)],\n",
       "              2: [('0439064864', 9.29),\n",
       "               ('0451191137', 9.0),\n",
       "               ('0590353403', 9.0),\n",
       "               ('0380814021', 8.83),\n",
       "               ('043935806X', 8.38),\n",
       "               ('0802132758', 8.25),\n",
       "               ('0439139597', 8.21),\n",
       "               ('0451523377', 8.0),\n",
       "               ('0671027344', 7.92),\n",
       "               ('0440237688', 7.83),\n",
       "               ('0345342968', 7.64),\n",
       "               ('0440222028', 7.5),\n",
       "               ('0446608955', 7.4),\n",
       "               ('0345339738', 7.38),\n",
       "               ('0385729332', 7.33),\n",
       "               ('0316666343', 7.13),\n",
       "               ('0439136350', 7.12),\n",
       "               ('0440219078', 7.0),\n",
       "               ('0064472272', 7.0),\n",
       "               ('0812550706', 7.0)],\n",
       "              3: [('0066238501', 9.86),\n",
       "               ('0394800389', 9.83),\n",
       "               ('0517693119', 9.83),\n",
       "               ('0920668364', 9.67),\n",
       "               ('0395177111', 9.5),\n",
       "               ('0316779059', 9.0),\n",
       "               ('0060256737', 8.83),\n",
       "               ('0345318587', 8.33),\n",
       "               ('0394800133', 8.25),\n",
       "               ('0786867906', 8.17),\n",
       "               ('0930289234', 8.17),\n",
       "               ('0064471063', 8.11),\n",
       "               ('0811807843', 8.0),\n",
       "               ('0451183940', 7.88),\n",
       "               ('0312423799', 7.67),\n",
       "               ('0060921056', 7.67),\n",
       "               ('0440900794', 7.67),\n",
       "               ('0886775957', 7.57),\n",
       "               ('0671720147', 7.5),\n",
       "               ('1563890119', 7.5)],\n",
       "              4: [('0553377868', 8.86),\n",
       "               ('1579546463', 8.0),\n",
       "               ('0380977311', 7.86),\n",
       "               ('0553379615', 7.83),\n",
       "               ('0446532452', 7.57),\n",
       "               ('0446322180', 7.29),\n",
       "               ('0439064864', 7.22),\n",
       "               ('0451169514', 7.17),\n",
       "               ('0553802461', 7.12),\n",
       "               ('0553268937', 6.83),\n",
       "               ('0553582763', 6.83),\n",
       "               ('0385318782', 6.71),\n",
       "               ('0679457526', 6.7),\n",
       "               ('0140053204', 6.7),\n",
       "               ('0140133488', 6.67),\n",
       "               ('0446611638', 6.64),\n",
       "               ('0679721037', 6.57),\n",
       "               ('0399146008', 6.56),\n",
       "               ('0449006565', 6.5),\n",
       "               ('0345458915', 6.5)],\n",
       "              5: [('1844262553', 8.0),\n",
       "               ('0439139597', 6.72),\n",
       "               ('0439136350', 6.55),\n",
       "               ('0439064864', 6.55),\n",
       "               ('0877017883', 6.19),\n",
       "               ('0618002227', 6.16),\n",
       "               ('0590353403', 6.13),\n",
       "               ('0671027344', 6.07),\n",
       "               ('0385199570', 5.93),\n",
       "               ('0771060548', 5.91),\n",
       "               ('0156528207', 5.78),\n",
       "               ('0618129022', 5.76),\n",
       "               ('0552128481', 5.68),\n",
       "               ('0552131059', 5.67),\n",
       "               ('0811801802', 5.65),\n",
       "               ('0670032379', 5.55),\n",
       "               ('0812550706', 5.52),\n",
       "               ('0375756981', 5.51),\n",
       "               ('0670894605', 5.42),\n",
       "               ('0811825558', 5.36)]}})"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for location in recommand_data.keys():\n",
    "    for age in recommand_data[location].keys():\n",
    "        print(location,age)\n",
    "        length=len(recommand_data[location][age])\n",
    "        recommand_data[location][age]+=top20_data[:20-length]\n",
    "recommand_data['italy'][5]=top20_data\n",
    "recommand_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "cPickle.dump(\n",
    "    recommand_data,\n",
    "    open('./data/recommand_data.pkl','wb')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
